import config from './config'

/**
 * Copyright (c) 2013-Now http://aidex.vip All rights reserved.
 */
// 此处第二个参数vm，就是我们在页面使用的this，你可以通过vm获取vuex等操作
const install = (Vue, vm) => {

	// 参数配置对象
	const config = vm.vuex_config;
	// 将各个定义的接口名称，统一放进对象挂载到vm.$u.api(因为vm就是this，也即this.$u.api)下
	vm.$u.api = {

		// 基础服务：登录登出、身份信息、菜单授权、切换系统、字典数据等
		lang: (params = {}) => vm.$u.get('/lang/' + params.lang),
		index: (params = {}) => vm.$u.get(config.adminPath + '/mobile/index', params),
		getUserInfo: (params = {}) => vm.$u.get(config.adminPath + '/mobile/user/getUserInfo', params),
		login: (params = {}) => vm.$u.post(config.adminPath + '/mobile/login/loginByPassword', params),
		sendCode: (params = {}) => vm.$u.post(config.adminPath + '/mobile/login/sendCode', params),
		registerUser: (params = {}) => vm.$u.post(config.adminPath + '/mobile/user/registerUser', params),

		logout: (params = {}) => vm.$u.get(config.adminPath + '/mobile/login/logout', params),
		authInfo: (params = {}) => vm.$u.get(config.adminPath + '/authInfo', params),
		menuTree: (params = {}) => vm.$u.get(config.adminPath + '/menuTree', params),
		switchSys: (params = {}) => vm.$u.get(config.adminPath + '/switch/' + params.sysCode),

		// 账号服务：验证码接口、忘记密码接口、注册账号接口等
		validCode: (params = {}) => vm.$u.getText('/validCode', params),
		getFpValidCode: (params = {}) => vm.$u.post('/account/getFpValidCode', params),
		savePwdByValidCode: (params = {}) => vm.$u.post('/account/savePwdByValidCode', params),
		getRegValidCode: (params = {}) => vm.$u.post('/account/getRegValidCode', params),
		saveRegByValidCode: (params = {}) => vm.$u.post('/account/saveRegByValidCode', params),

		getDetailByNoticeId: (params = {}) => vm.$u.get(config.adminPath + '/archives/notice/' + params),

		// APP公共服务
		upgradeCheck: () => vm.$u.post('/app/upgrade/check', {
			appCode: config.appCode,
			appVersion: config.appVersion
		}),
		commentSave: (params = {}) => vm.$u.post('/app/comment/save', params),

		/* 高德相关API */
		// GaodeWeatgerApi:(params = {})=> vm.$u.get('https://restapi.amap.com/v3/weather/weatherInfo',params),
		GaodeApi: {
			weather: (params = {}) => vm.$u.get(config.amapPath + '/weather/weatherInfo', params),
			coordinateConvert: (params = {}) => vm.$u.get(config.amapPath + '/assistant/coordinate/convert',
				params),
			inverseGeocode: (params = {}) => vm.$u.get(config.amapPath + '/geocode/regeo', params),
			searchKeyWord: (params = {}) => vm.$u.get(config.amapPath + '/assistant/inputtips', params),
			getIp: (params = {}) => vm.$u.get(config.amapPath + '/ip', params),
		},
		//  https://dev.qweather.com/
		qweather: {
			getCityInfo: (location = '') => vm.$u.get('https://geoapi.qweather.com/v2/city/lookup', {
				key: 'ffdc1f8c590e40c2b157539076ec2c8a',
				rang: 'cn',
				location
			}),
			history: (params = {}) => vm.$u.get('https://datasetapi.qweather.com/v7/historical/weather', {
				key: '3f278a73b95a41209ab91c167edc497d',
				...params
			}),
			// history: (location, date, unit = 'm') => {
			// 	let params = {
			// 		location,
			// 		date,
			// 		unit
			// 	}
			// 	console.log(params);
			// 	return vm.$u.get('https://datasetapi.qweather.com/v7/historical/weather', {
			// 		key: 'ffdc1f8c590e40c2b157539076ec2c8a',
			// 		...params
			// 	})
			// },
		},
		otherWeather: (location = '') => vm.$u.get('https://devapi.qweather.com/v7/weather/now', {
			key: 'ffdc1f8c590e40c2b157539076ec2c8a',
			location
		}),
		// 个人信息修改
		user: {
			saveUserInfo: (params = {}) => vm.$u.post(config.adminPath + '/mobile/user/saveUserInfo', params),
			infoSavePwd: (params = {}) => vm.$u.put(config.adminPath + '/system/user/profile/updatePwd',
				params),
			infoSavePqa: (params = {}) => vm.$u.post(config.adminPath + '/sys/user/infoSavePqa', params),
		},

		// 员工用户查询
		empUser: {
			listData: (params = {}) => vm.$u.get(config.adminPath + '/sys/empUser/listData', params),
		},

		// 组织机构查询
		office: {
			treeData: (params = {}) => vm.$u.get(config.adminPath + '/sys/office/treeData', params),
		},

		/* 用户信息 */
		systemUser: {
			list: (params = {}) => vm.$u.get(config.adminPath + '/system/user/list', params),
			get: (userId) => vm.$u.get(config.adminPath + `/system/user/${userId}`),
		},

		/* 字典相关 */
		systemDict: {
			query: (dictType) => vm.$u.get(config.adminPath + `/system/dict/data/type/${dictType}`),
		},

		/* 案卷相关 */
		archives: {
			add: (data = {}) => vm.$u.postJson(config.adminPath + '/archives/archives', data),
			edit: (data = {}) => vm.$u.putJson(config.adminPath + '/archives/archives', data),
			remove: (archivesIds) => vm.$u.delete(config.adminPath + `/archives/archives/${archivesIds}`),
			list: (params = {}, baseUrl = config.adminPath) => vm.$u.get(baseUrl + '/archives/archives/list',
				params),
			localList: (params = {}) => vm.$u.get('http://127.0.0.1:9010' + '/archives/archives/list', params, {
				isToken: false
			}),
			info: (params = {}) => vm.$u.get(config.adminPath + `/archives/archives/${params.archivesId}`,
				params),
			getModule: (archivesId) => vm.$u.get(config.adminPath +
				`/archives/archives/getModule/${archivesId}`),
			logList: (params = {}) => vm.$u.get(config.adminPath + '/archives/log/list', params),
			getPersonData: (data = {}) => vm.$u.postJson(config.adminPath + '/archives/notice/getPersonData',
				data),
			sendSyncData: (data = {}) => vm.$u.postJson(config.adminPath +
				`/archives/off_line/sendSynData/${data.archivesIds}`),
			getCommonData: (archivesId) => vm.$u.get(config.adminPath + `/archives/archives/getCommon/${archivesId}`)
		},

		record: {
			get: (id, option = {}) => vm.$u.get(config.adminPath + `/V2/archives/${option.moduleName}/${id}`),
			add: (data = {}, option = {}) => vm.$u.postJson(config.adminPath + `/V2/archives/${option.moduleName}`, data),
			edit: (data = {}, option = {}) => vm.$u.putJson(config.adminPath + `/V2/archives/${option.moduleName}`, data),
			info: (id, option = {}) => vm.$u.get(config.adminPath + `/V2/archives/${option.moduleName}/${id}`),
			list: (params = {}) => vm.$u.get(config.adminPath + '/archives/notice/list', params),
			remove: (moduleId, option) => vm.$u.delete(config.adminPath + `/V2/archives/${option.moduleName}/${moduleId}`),
			updateStagingStatus: (data = {}) => vm.$u.postJson(config.adminPath + '/archives/notice/updateStagingStatus', data),
			getDetailByNoticeId: (noticeId) => vm.$u.get(config.adminPath + `/archives/notice/${noticeId}`),
			downloadPdf: (data = {}, option = {}) => vm.$u.postJson(config.adminPath + `/V2/archives/${option.moduleName}/downloadPDF`, data),
		},
		/*
			询问笔记
		 */
		noteModule: {
			temObjList: (params = {}) => vm.$u.get(config.adminPath + '/archives/tem/list', params),
		},
		// 现场专业图
		specialty: {
			add: (params = {}) => vm.$u.postJson(config.adminPath + '/V2/archives/specialty', params),
			edit: (params = {}) => vm.$u.putJson(config.adminPath + '/V2/archives/specialty', params),
			details: id => vm.$u.get(config.adminPath + '/V2/archives/specialty/' + id),
		},
		// 现场草图
		sketchAPI: {
			add: (params = {}) => vm.$u.postJson(config.adminPath + '/V2/archives/sketch', params),
			edit: (params = {}) => vm.$u.putJson(config.adminPath + '/V2/archives/sketch', params),
			details: id => vm.$u.get(config.adminPath + '/V2/archives/sketch/' + id),
		},
		// 证据材料
		evidenceMaterial: {
			add: (params = {}) => vm.$u.postJson(config.adminPath + '/V2/archives/evidence', params),
			edit: (params = {}) => vm.$u.putJson(config.adminPath + '/V2/archives/evidence', params),
			details: id => vm.$u.get(config.adminPath + '/V2/archives/evidence/' + id),
		},
		// 火灾现场照片
		fireScenePhotos: {
			add: (params = {}) => vm.$u.postJson(config.adminPath + '/V2/archives/photo', params),
			edit: (params = {}) => vm.$u.putJson(config.adminPath + '/V2/archives/photo', params),
			details: id => vm.$u.get(config.adminPath + '/V2/archives/photo/' + id),
		},
		// 视频管理
		videoManagement: {
			add: (params = {}) => vm.$u.postJson(config.adminPath + '/V2/archives/video', params),
			edit: (params = {}) => vm.$u.putJson(config.adminPath + '/V2/archives/video', params),
			details: id => vm.$u.get(config.adminPath + '/V2/archives/video/' + id),
			timeAxis: noticeId => vm.$u.get(config.adminPath + '/V2/archives/video/getVideoList?noticeId=' + noticeId)
		},
		// 视频管理
		accidentAPI: {
			add: (params = {}) => vm.$u.postJson(config.adminPath + '/V2/archives/accident', params),
			edit: (params = {}) => vm.$u.putJson(config.adminPath + '/V2/archives/accident', params),
			details: id => vm.$u.get(config.adminPath + '/V2/archives/accident/' + id),
		},
		// 勘验笔录
		InquestIndexAPI: {
			add: (params = {}) => vm.$u.postJson(config.adminPath + '/V2/archives/inquest', params),
			edit: (params = {}) => vm.$u.putJson(config.adminPath + '/V2/archives/inquest', params),
			details: id => vm.$u.get(config.adminPath + '/V2/archives/inquest/' + id),
		},
		// 提取清单
		extractAPI: {
			add: (params = {}) => vm.$u.postJson(config.adminPath + '/V2/archives/extract', params),
			edit: (params = {}) => vm.$u.putJson(config.adminPath + '/V2/archives/extract', params),
			details: id => vm.$u.get(config.adminPath + '/V2/archives/extract/' + id),
		},
		// 损失清单
		lossAPI: {
			add: (params = {}) => vm.$u.postJson(config.adminPath + '/V2/archives/loss', params),
			edit: (params = {}) => vm.$u.putJson(config.adminPath + '/V2/archives/loss', params),
			details: id => vm.$u.get(config.adminPath + '/V2/archives/loss/' + id),
		},
		sketch: {
			getFileTabInfo: (params = {
				fileId: null
			}) => vm.$u.get(config.adminPath + `/V2/archives/sketch/getFileTabInfo`,
				params),
			getTabFileList: (params = {}) => vm.$u.get(config.adminPath + `/V2/archives/sketch/getTabFileList`,
				params),
			saveFileTab: (data = {}) => vm.$u.postJson(config.adminPath + `/V2/archives/sketch/saveFileTab`,
				data),
		},
		common: {
			uploadFile: (formData) => vm.$u.post(config.adminPath + `/common/upload`, {
				formData
			}, {
				'content-type': 'multipart/form-data;'
			}),
			uploadFileBase64: (base64) => vm.$u.post(config.adminPath + `/common/uploadByBase64`, {
				base64
			}, {
				'content-type': 'application/x-www-form-urlencoded'
			}),
		},
		// 仪器管理
		device: {
			list: (params = {}) => vm.$u.get(config.adminPath + '/archives/device/list', params),
		},
		deviceData: {
			add: (params = {}) => vm.$u.postJson(config.adminPath + '/archives/data', params),
		},
		// 分享
		share: {
			add: (params = {}) => vm.$u.postJson(config.adminPath + '/archives/share', params),
		},
		// 布控球相关
		imou: {
			getWarnList: (beginTime, endTime, count) => {
				const params = {
					beginTime,
					endTime,
					count
				}
				return vm.$u.get(config.adminPath + '/warning/getWaringList', params, {
					isToken: false
				})
			}
		},
		verison: {
			list: (params = {}) => vm.$u.get(config.adminPath + '/archives/verison/list', params),
		}
	};
}

export default {
	install
}